<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API文档 - 加密货币信息聚合系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            line-height: 1.6;
            color: #333;
            background-color: #f8f9fa;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 40px 0;
            text-align: center;
            margin-bottom: 40px;
            border-radius: 10px;
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
        }

        .header p {
            font-size: 1.2rem;
            opacity: 0.9;
        }

        .section {
            background: white;
            margin-bottom: 30px;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        .section h2 {
            color: #667eea;
            margin-bottom: 20px;
            font-size: 1.8rem;
            border-bottom: 2px solid #667eea;
            padding-bottom: 10px;
        }

        .section h3 {
            color: #555;
            margin: 20px 0 10px 0;
            font-size: 1.3rem;
        }

        .endpoint {
            background: #f8f9fa;
            border-left: 4px solid #667eea;
            padding: 15px;
            margin: 15px 0;
            border-radius: 5px;
        }

        .method {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-weight: bold;
            font-size: 0.9rem;
            margin-right: 10px;
        }

        .method.get { background: #28a745; color: white; }
        .method.post { background: #007bff; color: white; }
        .method.put { background: #ffc107; color: black; }
        .method.delete { background: #dc3545; color: white; }

        .url {
            font-family: 'Courier New', monospace;
            background: #e9ecef;
            padding: 2px 6px;
            border-radius: 3px;
            font-size: 0.95rem;
        }

        .params {
            margin-top: 10px;
        }

        .param {
            margin: 5px 0;
            font-size: 0.9rem;
        }

        .param-name {
            font-weight: bold;
            color: #667eea;
        }

        .param-type {
            color: #6c757d;
            font-style: italic;
        }

        .example {
            background: #2d3748;
            color: #e2e8f0;
            padding: 15px;
            border-radius: 5px;
            margin: 10px 0;
            overflow-x: auto;
        }

        .example pre {
            margin: 0;
            font-family: 'Courier New', monospace;
            font-size: 0.9rem;
        }

        .nav {
            background: white;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        .nav ul {
            list-style: none;
            display: flex;
            flex-wrap: wrap;
            gap: 20px;
        }

        .nav a {
            color: #667eea;
            text-decoration: none;
            font-weight: 500;
            padding: 8px 16px;
            border-radius: 5px;
            transition: background-color 0.3s;
        }

        .nav a:hover {
            background-color: #f8f9fa;
        }

        .back-link {
            display: inline-block;
            margin-bottom: 20px;
            color: #667eea;
            text-decoration: none;
            font-weight: 500;
        }

        .back-link:hover {
            text-decoration: underline;
        }

        @media (max-width: 768px) {
            .container {
                padding: 10px;
            }
            
            .header h1 {
                font-size: 2rem;
            }
            
            .section {
                padding: 20px;
            }
            
            .nav ul {
                flex-direction: column;
                gap: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <a href="/" class="back-link">← 返回主页</a>
        
        <div class="header">
            <h1>🚀 API文档</h1>
            <p>加密货币信息聚合系统 RESTful API</p>
        </div>

        <nav class="nav">
            <ul>
                <li><a href="#overview">概览</a></li>
                <li><a href="#authentication">认证</a></li>
                <li><a href="#endpoints">接口列表</a></li>
                <li><a href="#examples">示例</a></li>
                <li><a href="#errors">错误处理</a></li>
            </ul>
        </nav>

        <section class="section" id="overview">
            <h2>📋 API概览</h2>
            <p><strong>Base URL:</strong> <span class="url">http://localhost:3000/api</span></p>
            <p><strong>数据格式:</strong> JSON</p>
            <p><strong>字符编码:</strong> UTF-8</p>
            <p><strong>请求方法:</strong> GET, POST</p>
            
            <h3>响应格式</h3>
            <div class="example">
                <pre>{
  "success": true,
  "data": { ... },
  "message": "操作成功",
  "timestamp": "2024-01-01T00:00:00.000Z"
}</pre>
            </div>
        </section>

        <section class="section" id="authentication">
            <h2>🔐 认证</h2>
            <p>当前版本的API不需要认证，所有接口都是公开访问的。</p>
            <p><strong>注意:</strong> 在生产环境中，建议添加适当的认证和限流机制。</p>
        </section>

        <section class="section" id="endpoints">
            <h2>🔗 接口列表</h2>

            <h3>系统接口</h3>
            
            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/health</span>
                <p>获取系统健康状态</p>
            </div>

            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/summary</span>
                <p>获取系统数据概览</p>
            </div>

            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/stats</span>
                <p>获取系统统计信息</p>
            </div>

            <h3>代币接口</h3>
            
            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/tokens</span>
                <p>获取代币列表</p>
                <div class="params">
                    <div class="param">
                        <span class="param-name">symbol</span>
                        <span class="param-type">(string, 可选)</span>
                        - 代币符号过滤
                    </div>
                    <div class="param">
                        <span class="param-name">category</span>
                        <span class="param-type">(string, 可选)</span>
                        - 分类过滤 (large_cap, mid_cap, small_cap, micro_cap)
                    </div>
                    <div class="param">
                        <span class="param-name">minScore</span>
                        <span class="param-type">(number, 可选)</span>
                        - 最小评分 (0-100)
                    </div>
                    <div class="param">
                        <span class="param-name">maxScore</span>
                        <span class="param-type">(number, 可选)</span>
                        - 最大评分 (0-100)
                    </div>
                    <div class="param">
                        <span class="param-name">sortBy</span>
                        <span class="param-type">(string, 可选)</span>
                        - 排序字段 (score, avgPrice, avgVolume24h, avgMarketCap)
                    </div>
                    <div class="param">
                        <span class="param-name">order</span>
                        <span class="param-type">(string, 可选)</span>
                        - 排序方向 (asc, desc)
                    </div>
                    <div class="param">
                        <span class="param-name">limit</span>
                        <span class="param-type">(number, 可选)</span>
                        - 返回数量限制 (默认: 50)
                    </div>
                    <div class="param">
                        <span class="param-name">offset</span>
                        <span class="param-type">(number, 可选)</span>
                        - 偏移量 (默认: 0)
                    </div>
                </div>
            </div>

            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/tokens/{symbol}</span>
                <p>获取特定代币详情</p>
            </div>

            <h3>聪明钱接口</h3>
            
            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/smart-money</span>
                <p>获取聪明钱列表</p>
                <div class="params">
                    <div class="param">
                        <span class="param-name">minScore</span>
                        <span class="param-type">(number, 可选)</span>
                        - 最小智能评分 (0-100)
                    </div>
                    <div class="param">
                        <span class="param-name">maxScore</span>
                        <span class="param-type">(number, 可选)</span>
                        - 最大智能评分 (0-100)
                    </div>
                    <div class="param">
                        <span class="param-name">riskLevel</span>
                        <span class="param-type">(string, 可选)</span>
                        - 风险等级 (low, medium, high, very_high)
                    </div>
                    <div class="param">
                        <span class="param-name">tags</span>
                        <span class="param-type">(string, 可选)</span>
                        - 标签过滤 (逗号分隔)
                    </div>
                    <div class="param">
                        <span class="param-name">sortBy</span>
                        <span class="param-type">(string, 可选)</span>
                        - 排序字段 (smartScore, avgPnl7d, avgPnl30d)
                    </div>
                    <div class="param">
                        <span class="param-name">order</span>
                        <span class="param-type">(string, 可选)</span>
                        - 排序方向 (asc, desc)
                    </div>
                    <div class="param">
                        <span class="param-name">limit</span>
                        <span class="param-type">(number, 可选)</span>
                        - 返回数量限制 (默认: 20)
                    </div>
                    <div class="param">
                        <span class="param-name">offset</span>
                        <span class="param-type">(number, 可选)</span>
                        - 偏移量 (默认: 0)
                    </div>
                </div>
            </div>

            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/smart-money/{address}</span>
                <p>获取特定钱包详情</p>
            </div>

            <h3>市场数据接口</h3>
            
            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/market-data</span>
                <p>获取市场总体数据</p>
            </div>

            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/trends</span>
                <p>获取市场趋势分析</p>
            </div>

            <h3>风险分析接口</h3>
            
            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/risks</span>
                <p>获取风险分析报告</p>
                <div class="params">
                    <div class="param">
                        <span class="param-name">severity</span>
                        <span class="param-type">(string, 可选)</span>
                        - 严重程度过滤 (low, medium, high, critical)
                    </div>
                    <div class="param">
                        <span class="param-name">type</span>
                        <span class="param-type">(string, 可选)</span>
                        - 风险类型过滤
                    </div>
                </div>
            </div>

            <h3>搜索接口</h3>
            
            <div class="endpoint">
                <span class="method get">GET</span>
                <span class="url">/api/search</span>
                <p>搜索代币和钱包</p>
                <div class="params">
                    <div class="param">
                        <span class="param-name">q</span>
                        <span class="param-type">(string, 必需)</span>
                        - 搜索关键词 (至少2个字符)
                    </div>
                    <div class="param">
                        <span class="param-name">type</span>
                        <span class="param-type">(string, 可选)</span>
                        - 搜索类型 (all, tokens, smartMoney)
                    </div>
                    <div class="param">
                        <span class="param-name">limit</span>
                        <span class="param-type">(number, 可选)</span>
                        - 返回数量限制 (默认: 20)
                    </div>
                </div>
            </div>

            <h3>数据管理接口</h3>
            
            <div class="endpoint">
                <span class="method post">POST</span>
                <span class="url">/api/refresh</span>
                <p>手动刷新数据</p>
            </div>
        </section>

        <section class="section" id="examples">
            <h2>💡 使用示例</h2>

            <h3>获取系统概览</h3>
            <div class="example">
                <pre>curl -X GET "http://localhost:3000/api/summary"</pre>
            </div>

            <h3>搜索BTC相关信息</h3>
            <div class="example">
                <pre>curl -X GET "http://localhost:3000/api/search?q=BTC&type=tokens"</pre>
            </div>

            <h3>获取高评分代币</h3>
            <div class="example">
                <pre>curl -X GET "http://localhost:3000/api/tokens?minScore=90&sortBy=score&order=desc&limit=10"</pre>
            </div>

            <h3>获取低风险聪明钱</h3>
            <div class="example">
                <pre>curl -X GET "http://localhost:3000/api/smart-money?riskLevel=low&sortBy=smartScore&order=desc"</pre>
            </div>

            <h3>JavaScript示例</h3>
            <div class="example">
                <pre>// 获取代币列表
fetch('/api/tokens?limit=10')
  .then(response => response.json())
  .then(data => {
    if (data.success) {
      console.log('代币数据:', data.data.tokens);
    }
  })
  .catch(error => console.error('错误:', error));

// 搜索功能
async function searchTokens(keyword) {
  try {
    const response = await fetch(`/api/search?q=${encodeURIComponent(keyword)}&type=tokens`);
    const data = await response.json();
    return data.success ? data.data : null;
  } catch (error) {
    console.error('搜索失败:', error);
    return null;
  }
}</pre>
            </div>
        </section>

        <section class="section" id="errors">
            <h2>⚠️ 错误处理</h2>

            <h3>HTTP状态码</h3>
            <ul>
                <li><strong>200</strong> - 请求成功</li>
                <li><strong>400</strong> - 请求参数错误</li>
                <li><strong>404</strong> - 资源未找到</li>
                <li><strong>500</strong> - 服务器内部错误</li>
            </ul>

            <h3>错误响应格式</h3>
            <div class="example">
                <pre>{
  "success": false,
  "error": "错误描述信息",
  "code": "ERROR_CODE",
  "timestamp": "2024-01-01T00:00:00.000Z"
}</pre>
            </div>

            <h3>常见错误</h3>
            <ul>
                <li><strong>INVALID_PARAMETER</strong> - 参数格式错误</li>
                <li><strong>RESOURCE_NOT_FOUND</strong> - 资源不存在</li>
                <li><strong>SEARCH_KEYWORD_TOO_SHORT</strong> - 搜索关键词太短</li>
                <li><strong>INTERNAL_SERVER_ERROR</strong> - 服务器内部错误</li>
            </ul>
        </section>

        <div class="section">
            <h2>📞 技术支持</h2>
            <p>如果您在使用API过程中遇到问题，请：</p>
            <ul>
                <li>检查请求参数是否正确</li>
                <li>确认服务器是否正常运行</li>
                <li>查看服务器日志获取详细错误信息</li>
                <li>联系技术支持团队</li>
            </ul>
        </div>
    </div>
</body>
</html>

